-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Span`1+Enumerator.xml
195 lines (175 loc) · 12.8 KB
/
Span`1+Enumerator.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<Type Name="Span<T>+Enumerator" FullName="System.Span<T>+Enumerator">
<TypeSignature Language="C#" Value="public ref struct Span<T>.Enumerator" />
<TypeSignature Language="ILAsm" Value=".class nested public sequential ansi sealed beforefieldinit Span`1/Enumerator<T> extends System.ValueType" />
<TypeSignature Language="DocId" Value="T:System.Span`1.Enumerator" />
<TypeSignature Language="VB.NET" Value="Public Structure Span(Of T).Enumerator" />
<TypeSignature Language="F#" Value="type Span<'T>.Enumerator = struct" />
<TypeSignature Language="C++ CLI" Value="public: value class Span<T>::Enumerator" />
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Memory</AssemblyName>
<AssemblyVersion>4.0.1.2</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="System.Memory" FromVersion="5.0.0.0" To="System.Runtime" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="System.Memory" FromVersion="6.0.0.0" To="System.Runtime" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="System.Memory" FromVersion="7.0.0.0" To="System.Runtime" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="System.Memory" FromVersion="8.0.0.0" To="System.Runtime" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
<TypeForwarding From="System.Memory" FromVersion="9.0.0.0" To="System.Runtime" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
<TypeForwarding From="System.Memory" FromVersion="4.1.0.0" To="System.Runtime" ToVersion="4.2.1.0" FrameworkAlternate="netcore-2.1;netcore-2.2" />
<TypeForwarding From="System.Memory" FromVersion="4.2.0.0" To="System.Runtime" ToVersion="4.2.1.0" FrameworkAlternate="netcore-3.0" />
<TypeForwarding From="System.Memory" FromVersion="4.2.1.0" To="System.Runtime" ToVersion="4.2.2.0" FrameworkAlternate="netcore-3.1" />
</TypeForwardingChain>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Base>
<BaseTypeName>System.ValueType</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netstandard-2.1">
<AttributeName Language="C#">[System.Runtime.CompilerServices.IsByRefLike]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.IsByRefLike>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.CompilerFeatureRequired("RefStructs")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.CompilerFeatureRequired("RefStructs")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Provides an enumerator for the elements of a <see cref="T:System.Span`1" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
The C# [foreach](/dotnet/csharp/language-reference/keywords/foreach-in) of the C# language and the [For Each...Next](/dotnet/visual-basic/language-reference/statements/for-each-next-statement) construct in Visual Basic hides the complexity of enumerators. Instead of directly manipulating the enumerator, using `foreach` or `For Each...Next` is recommended.
Initially, the enumerator is positioned before the first element in the <xref:System.Span%601>. At this position, <xref:System.Span%601.Enumerator.Current> is undefined. You must call <xref:System.Span%601.Enumerator.MoveNext%2A> to advance the enumerator to the first item in the <xref:System.Span%601> before reading the value of <xref:System.Span%601.Enumerator.Current>.
<xref:System.Span%601.Enumerator.Current> returns the same value until <xref:System.Span%601.Enumerator.MoveNext%2A> is called. <xref:System.Span%601.Enumerator.MoveNext%2A> sets <xref:System.Span%601.Enumerator.Current> to the next item in the <xref:System.Span%601>.
If <xref:System.Span%601.Enumerator.MoveNext%2A> passes the end of the <xref:System.Span%601>, <xref:System.Span%601.Enumerator.MoveNext%2A> returns `false`. When the enumerator is at this state, subsequent calls to <xref:System.Span%601.Enumerator.MoveNext%2A> also return `false` and <xref:System.Span%601.Enumerator.Current> is undefined. You cannot set <xref:System.Span%601.Enumerator.Current> to the first item in the <xref:System.Span%601> again; you must create a new enumerator instance instead.
The enumerator does not have exclusive access to the <xref:System.Span%601>. In addition, the underlying data on which the span is based can also be modified. Therefore, enumerating through a span is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you must implement your own synchronization. For example, the following code has a race condition. It does not ensure that the span will be enumerated before the `ClearContents` method executes. As a result, the underlying array is cleared during enumeration of the span:
:::code language="csharp" source="~/snippets/csharp/System/Span.Enumerator/Program.cs":::
:::code language="fsharp" source="~/snippets/fsharp/System/Span.Enumerator/Program.fs":::
If you synchronize access to the array before enumerating the span, as the revised version of the `EnumerateSpan` method does in the following example, the `ClearContents` method doesn't modify underlying span data during enumeration. Note that the example locks the underlying array on which the span is based.
:::code language="csharp" source="~/snippets/csharp/System/Span.Enumerator/Program2.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/Span.Enumerator/Program2.fs" id="Snippet1":::
Unlike some other enumerator structures in .NET, the <xref:System.Span%601.Enumerator>:
- Does not implement the <xref:System.Collections.IEnumerator> or <xref:System.Collections.Generic.IEnumerator%601> interface. This is because <xref:System.Span%601.Enumerator> is a [ref struct](/dotnet/csharp/reference-semantics-with-value-types#ref-struct-type).
- Does not include a `Reset` method, which can set the enumerator to its initial position before the first element in the span. (The <xref:System.Collections.IEnumerator.Reset?displayProperty=nameWithType> method must be implemented as part of the interface, but most implementors either throw an exception or provide no implementation.)
]]></format>
</remarks>
</Docs>
<Members>
<Member MemberName="Current">
<MemberSignature Language="C#" Value="public ref T Current { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance !T Current" />
<MemberSignature Language="DocId" Value="P:System.Span`1.Enumerator.Current" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Current As T" />
<MemberSignature Language="F#" Value="member this.Current : 'T" Usage="System.Span<'T>.Enumerator.Current" />
<MemberSignature Language="C++ CLI" Value="public:
 property T % Current { T % get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Memory</AssemblyName>
<AssemblyVersion>4.0.1.2</AssemblyVersion>
</AssemblyInfo>
<ReturnValue RefType="Ref">
<ReturnType>T</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a reference to the item at the current position of the enumerator.</summary>
<value>The element in the <see cref="T:System.Span`1" /> at the current position of the enumerator.</value>
<remarks>
<format type="text/markdown"><![CDATA[
`Current` is undefined under either of the following conditions:
- Immediately after the enumerator is created, the enumerator is positioned before the first element in the span. <xref:System.Span%601.Enumerator.MoveNext%2A> must be called to advance the enumerator to the first element of the span before reading the value of `Current`.
- The last call to <xref:System.Span%601.Enumerator.MoveNext%2A> returned `false`, which indicates the end of the span.
`Current` returns the same value until <xref:System.Span%601.Enumerator.MoveNext%2A> is called. <xref:System.Span%601.Enumerator.MoveNext%2A> sets `Current` to the next item in the span.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="MoveNext">
<MemberSignature Language="C#" Value="public bool MoveNext ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance bool MoveNext() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Span`1.Enumerator.MoveNext" />
<MemberSignature Language="VB.NET" Value="Public Function MoveNext () As Boolean" />
<MemberSignature Language="F#" Value="member this.MoveNext : unit -> bool" Usage="enumerator.MoveNext " />
<MemberSignature Language="C++ CLI" Value="public:
 bool MoveNext();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Memory</AssemblyName>
<AssemblyVersion>4.0.1.2</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Advances the enumerator to the next item of the <see cref="T:System.Span`1" />.</summary>
<returns>
<see langword="true" /> if the enumerator successfully advanced to the next item; <see langword="false" /> if the end of the span has been passed.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
After an enumerator is created, it is positioned before the first element in the span, and the first call to `MoveNext` advances the enumerator to the first item in the span.
If `MoveNext` passes the end of the span, `MoveNext` returns `false`. When the enumerator is at this state, subsequent calls to `MoveNext` also return `false`.
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>